#include "classes/Command.hpp"
#include "classes/MapClass.hpp"
#include "classes/PlayerClass.hpp"
Commands::Commands()
{

}
Commands::~Commands()
{

}
void Commands::Move(int Direction)
{
    if(Direction==NORTH)
    {
        if (gPlayer->GetCoords().y>0)
        {
            if(gMap->GetRoom(gPlayer->GetCoords().x,gPlayer->GetCoords().y-1,gPlayer->GetCoords().z)->NonRoom==false)
            {
                if(gMap->GetRoom(gPlayer->GetCoords().x,gPlayer->GetCoords().y,gPlayer->GetCoords().z)->NorthExit.isOpen==true)
                {
                    gPlayer->SetCoords(sf::Vector3i(gPlayer->GetCoords().x,gPlayer->GetCoords().y-1,gPlayer->GetCoords().z));
                    gMainWindow->NewLine("You go north.");
                    Look();
                    return;
                }
            }
        }
    }
    else if(Direction==EAST)
    {
        if (gPlayer->GetCoords().x<MAP_WIDTH-1)
        {
            if(gMap->GetRoom(gPlayer->GetCoords().x+1,gPlayer->GetCoords().y,gPlayer->GetCoords().z)->NonRoom==false)
            {
                if(gMap->GetRoom(gPlayer->GetCoords().x,gPlayer->GetCoords().y,gPlayer->GetCoords().z)->EastExit.isOpen==true)
                {
                    gPlayer->SetCoords(sf::Vector3i(gPlayer->GetCoords().x+1,gPlayer->GetCoords().y,gPlayer->GetCoords().z));
                    gMainWindow->NewLine("You go east.");
                    Look();
                    return;
                }
            }
        }
    }
    else if(Direction==SOUTH)
    {
        if (gPlayer->GetCoords().y<MAP_HEIGHT-1)
        {
            if(gMap->GetRoom(gPlayer->GetCoords().x,gPlayer->GetCoords().y+1,gPlayer->GetCoords().z)->NonRoom==false)
            {
                if(gMap->GetRoom(gPlayer->GetCoords().x,gPlayer->GetCoords().y,gPlayer->GetCoords().z)->SouthExit.isOpen==true)
                {
                    gPlayer->SetCoords(sf::Vector3i(gPlayer->GetCoords().x,gPlayer->GetCoords().y+1,gPlayer->GetCoords().z));
                    gMainWindow->NewLine("You go south.");
                    Look();
                    return;
                }

            }
        }
    }
    else if(Direction==WEST)
    {
        if (gPlayer->GetCoords().x>0)
        {
            if(gMap->GetRoom(gPlayer->GetCoords().x-1,gPlayer->GetCoords().y,gPlayer->GetCoords().z)->NonRoom==false)
            {
                if(gMap->GetRoom(gPlayer->GetCoords().x,gPlayer->GetCoords().y,gPlayer->GetCoords().z)->WestExit.isOpen==true)
                {
                    gPlayer->SetCoords(sf::Vector3i(gPlayer->GetCoords().x-1,gPlayer->GetCoords().y,gPlayer->GetCoords().z));
                    gMainWindow->NewLine("You go west.");
                    Look();
                    return;
                }
            }
        }
    }
	else if(Direction==DOWN)
    {
		if (gPlayer->GetCoords().z<MAP_DEPTH)
        {
            if(gMap->GetRoom(gPlayer->GetCoords().x,gPlayer->GetCoords().y,gPlayer->GetCoords().z+1)->NonRoom==false)
            {
                if(gMap->GetRoom(gPlayer->GetCoords().x,gPlayer->GetCoords().y,gPlayer->GetCoords().z)->DownExit.isOpen==true)
                {
                    gPlayer->SetCoords(sf::Vector3i(gPlayer->GetCoords().x,gPlayer->GetCoords().y,gPlayer->GetCoords().z+1));
                    gMainWindow->NewLine("You go down.");
                    Look();
                    return;
                }
            }
        }
    }
	else if(Direction==UP)
    {
		if (gPlayer->GetCoords().z>0)
        {
            if(gMap->GetRoom(gPlayer->GetCoords().x,gPlayer->GetCoords().y,gPlayer->GetCoords().z-1)->NonRoom==false)
            {
                if(gMap->GetRoom(gPlayer->GetCoords().x,gPlayer->GetCoords().y,gPlayer->GetCoords().z)->UpExit.isOpen==true)
                {
                    gPlayer->SetCoords(sf::Vector3i(gPlayer->GetCoords().x,gPlayer->GetCoords().y,gPlayer->GetCoords().z-1));
                    gMainWindow->NewLine("You go up.");
                    Look();
                    return;
                }
            }
        }
    }
    gMainWindow->NewLine("Cannot go that direction.");
}
void Commands::Look()
{
	std::string output;
	output=">: ";
	output+=gMap->GetRoom(gPlayer->GetCoords().x,gPlayer->GetCoords().y,gPlayer->GetCoords().z)->Description;
	output+=" ";
	gMainWindow->NewLine(output);
	output=">: ";
	output+=gMap->GetRoom(gPlayer->GetCoords().x,gPlayer->GetCoords().y,gPlayer->GetCoords().z)->NorthExit.Description;
	output+=" ";
	output+=gMap->GetRoom(gPlayer->GetCoords().x,gPlayer->GetCoords().y,gPlayer->GetCoords().z)->EastExit.Description;
	output+=" ";
	output+=gMap->GetRoom(gPlayer->GetCoords().x,gPlayer->GetCoords().y,gPlayer->GetCoords().z)->SouthExit.Description;
	output+=" ";
	output+=gMap->GetRoom(gPlayer->GetCoords().x,gPlayer->GetCoords().y,gPlayer->GetCoords().z)->WestExit.Description;
	output+=" ";
	output+=gMap->GetRoom(gPlayer->GetCoords().x,gPlayer->GetCoords().y,gPlayer->GetCoords().z)->UpExit.Description;
	output+=" ";
	output+=gMap->GetRoom(gPlayer->GetCoords().x,gPlayer->GetCoords().y,gPlayer->GetCoords().z)->DownExit.Description;
	gMainWindow->NewLine(output);
}
